/*    */ package com.qmsk.business.member.memberQr.controller;
/*    */ 
/*    */ import com.qmsk.business.member.member.dao.MemberDAO;
/*    */ import com.qmsk.business.member.shopMember.dao.ShopMemberDAO;
/*    */ import com.swetake.util.Qrcode;
/*    */ import com.utils.basic.CFileComm;
/*    */ import com.utils.file.GlobalParams;
/*    */ import com.utils.gson.in.GsonHeadOneRow;
/*    */ import com.utils.web.ResponseUtils;
/*    */ import java.awt.Color;
/*    */ import java.awt.Graphics2D;
/*    */ import java.awt.image.BufferedImage;
/*    */ import java.io.File;
/*    */ import javax.imageio.ImageIO;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import org.apache.commons.lang.StringUtils;
/*    */ import org.apache.log4j.Logger;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.stereotype.Controller;
/*    */ import org.springframework.web.bind.annotation.PathVariable;
/*    */ import org.springframework.web.bind.annotation.RequestMapping;
/*    */ 
/*    */ @Controller
/*    */ @RequestMapping({"Qr"})
/*    */ public class NewQrController
/*    */ {
/* 31 */   private static final Logger logger = Logger.getLogger(NewQrController.class);
/*    */ 
/*    */   @Autowired
/*    */   private ShopMemberDAO shopMemberDao;
/*    */ 
/*    */   @Autowired
/*    */   private MemberDAO memberDao;
/*    */ 
/*    */   @RequestMapping(value={"insertQR/{openId}/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*    */   public void insertQR(HttpServletRequest request, HttpServletResponse response, @PathVariable("openId") String openId, @PathVariable("shopId") Long shopId)
/*    */     throws Exception
/*    */   {
/* 45 */     Long memberId = this.memberDao.getMemberIdOfOpenId(openId, shopId);
/* 46 */     GsonHeadOneRow qr = this.shopMemberDao.getMemberInfoOfMemberId(memberId, 
/* 47 */       shopId);
/* 48 */     if (qr != null) {
/* 49 */       String mCardNo = (String)qr.getValueOfName("MemberCardNo");
/* 50 */       if (StringUtils.isEmpty(mCardNo)) {
/* 51 */         ResponseUtils.setErrorMsgResponse("鐢熸垚浜岀淮鐮佸け璐�", response);
/* 52 */         return;
/*    */       }
/*    */       try
/*    */       {
/* 56 */         Qrcode qrcode = new Qrcode();
/* 57 */         qrcode.setQrcodeErrorCorrect('M');
/* 58 */         qrcode.setQrcodeEncodeMode('B');
/* 59 */         qrcode.setQrcodeVersion(4);
/* 60 */         int size = 103;
/* 61 */         byte[] d = mCardNo.getBytes("UTF-8");
/*    */ 
/* 63 */         BufferedImage bi = new BufferedImage(size, size, 
/* 64 */           1);
/*    */ 
/* 67 */         Graphics2D g = bi.createGraphics();
/*    */ 
/* 70 */         g.setBackground(Color.WHITE);
/* 71 */         g.clearRect(0, 0, size, size);
/*    */ 
/* 73 */         g.setColor(Color.BLACK);
/*    */ 
/* 75 */         if ((d.length > 0) && (d.length < 123)) {
/* 76 */           boolean[][] b = qrcode.calQrcode(d);
/*    */ 
/* 78 */           for (int i = 0; i < b.length; ++i)
/*    */           {
/* 80 */             for (int j = 0; j < b.length; ++j) {
/* 81 */               if (b[j][i] != false) {
/* 82 */                 g.fillRect(j * 3 + 2, i * 3 + 2, 3, 3);
/*    */               }
/*    */             }
/*    */           }
/*    */ 
/*    */         }
/*    */ 
/* 89 */         g.dispose();
/* 90 */         bi.flush();
/*    */ 
/* 92 */         File fileName = new File(GlobalParams.getGlobalParams()
/* 93 */           .getApacheRoot() + 
/* 94 */           "qr/" + 
/* 95 */           shopId + 
/* 96 */           "/memberId/" + 
/* 97 */           memberId + "/1.jpg");
/* 98 */         logger.error("鍐欏叆璺緞锛�" + GlobalParams.getGlobalParams()
/* 99 */           .getApacheRoot() + 
/* 100 */           "qr/" + 
/* 101 */           shopId + 
/* 102 */           "/memberId/" + 
/* 103 */           memberId + "/1.jpg");
/* 104 */         if (!(fileName.exists())) {
/* 105 */           fileName.mkdirs();
/*    */ 
/* 107 */           CFileComm.setExecutablePermission(fileName);
/*    */         }
/*    */ 
/* 110 */         ImageIO.write(bi, "jpg", fileName);
/*    */ 
/* 112 */         String qrUrl = GlobalParams.getGlobalParams().getApacheUrl() + 
/* 113 */           "qr/" + shopId + "/memberId/" + memberId + 
/* 114 */           "/1.jpg";
/* 115 */         logger.error("杈撳嚭璺緞锛�" + qrUrl);
/* 116 */         ResponseUtils.toGsonEbRst(new String[] { "qrUrl" }, 
/* 117 */           new Object[] { qrUrl }, response);
/*    */       } catch (Exception e) {
/* 119 */         logger.error(e);
/* 120 */         ResponseUtils.setErrorMsgResponse("鐢熸垚浜岀淮鐮佸け璐�", response);
/*    */       }
/*    */     } else {
/* 123 */       ResponseUtils.setErrorMsgResponse("鏈壘鍒扮鍚堟潯浠剁殑鏁版嵁", response);
/*    */     }
/*    */   }
/*    */ }

/* Location:           C:\Users\Administrator\Desktop\鏂板缓鏂囦欢澶筡WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.member.memberQr.controller.NewQrController
 * JD-Core Version:    0.5.3
 */